const Koa = require('koa');
const app = new Koa();
const json = require('koa-json');
const router = require('koa-router')();
const cors = require('koa2-cors');
const abnormal = require('./config/abnormal.js');
const { koaBody } = require('koa-body');
app.use(cors());
app.use(json());
app.use(abnormal);
app.use(koaBody({
	multipart: true,
	formidable: {
		uploadDir: './static/uploads/',
		maxFileSize: 2000 * 1024 * 1024,
		keepExtensions: true
	}
}));
// 全局异常处理

// 编辑公告
const updateannouncement = require('./router/announcement/updateannouncement.js');
// 删除公告
const deleteannouncement = require('./router/announcement/deleteannouncement.js');
// 发布公告
const addannouncement = require('./router/announcement/addannouncement.js');
// 查询公告
const queryannouncement = require('./router/announcement/queryannouncement.js');
// 查询党员信息
const userlist = require('./router/user/userlist.js');
// 添加党员信息
const adduserlist = require('./router/user/adduserlist.js');
// 删除党员信息
const deleteuserlist = require('./router/user/deleteuserlist.js');
// 修改党员信息
const edituserlist = require('./router/user/edituserlist.js');
// 添加党建活动
const addactivity = require('./router/activity/addactivity.js');
// 查询所有党建活动
const activitylist = require('./router/activity/activitylist.js');
// 删除党建活动
const deleteactivity = require('./router/activity/deleteactivity.js');
// 修改党建活动
const editactivity = require('./router/activity/editactivity.js');
// 查询全部报名党员信息
const participants = require('../koa/router/activity/participants.js');
// 上传文件
const upload = require('./router/learningdatas/upload.js');
// 查询根目录下所有文件
const rootdirectory = require('./router/learningdatas/rootdirectory.js');
// 新建文件夹
const createnewfolder = require('./router/learningdatas/createnewfolder.js');
// 删除单个文件夹/文件
const deletefileorfolder = require('./router/learningdatas/deletefileorfolder.js');
// 给文件/文件夹重命名
const rename = require('./router/learningdatas/rename.js');
// 批量删除文件/文件夹
const multipledelete = require('./router/learningdatas/multipledelete.js');
// 下载单个文件
const downloadfileorfolder = require('./router/learningdatas/downloadfileorfolder.js');
// 下载多个文件
const multipledownload = require('./router/learningdatas/multipledownload.js');
// 查询所有帖子
const queryalltopic = require('./router/topic/queryalltopic.js')
// 添加帖子
const addtopic = require('./router/topic/addtopic.js')
// 更新帖子
const updatetopic = require('./router/topic/updatetopic.js')
// 审核帖子
const audittopic = require('./router/topic/audittopic.js')
// 删除帖子
const deletetopic = require('./router/topic/deletetopic.js')
// 审核文件/文件夹
const auditfileorfolder = require('./router/learningdatas/auditfileorfolder.js')
// 获取文件临时路径
const getfiletempurl = require('./router/topic/getfiletempurl.js')
// 上传帖子封面
const uploadpic = require('./router/topic/uploadpic.js')
// 查询一级评论
const queryallcomment = require('./router/topic/queryallcomment.js')
// 查询评论用户
const queryuser = require('./router/topic/queryuser.js')
// 配置路由接口
router.use('/api', updateannouncement);
router.use('/api', deleteannouncement);
router.use('/api', addannouncement);
router.use('/api', queryannouncement);
router.use('/api', userlist);
router.use('/api', adduserlist);
router.use('/api', deleteuserlist);
router.use('/api', edituserlist);
router.use('/api', addactivity);
router.use('/api', activitylist);
router.use('/api', deleteactivity);
router.use('/api', editactivity);
router.use('/api', participants);
router.use('/api', upload);
router.use('/api', rootdirectory);
router.use('/api', createnewfolder);
router.use('/api', deletefileorfolder);
router.use('/api', rename);
router.use('/api', multipledelete);
router.use('/api', downloadfileorfolder);
router.use('/api', multipledownload);
router.use('/api', queryalltopic);
router.use('/api', addtopic);
router.use('/api', updatetopic);
router.use('/api', deletetopic);
router.use('/api', auditfileorfolder);
router.use('/api', getfiletempurl);
router.use('/api', uploadpic);
router.use('/api', queryallcomment);
router.use('/api', queryuser);
router.use('/api', audittopic);
// 启动路由
app.use(router.routes()).use(router.allowedMethods());
// 自定义端口号
app.listen(3000);
console.log('服务器启动成功,端口号：3000');